package com.pdf.demo.util;

import org.apache.commons.lang3.StringUtils;

public class EvaluateUtil {

    private static String styleStatus(String name) {
        return "<span style=\"color: red\">" + name + "</span>";
    }

    //身高-评价
    public static String heightEvaluate() {
        return "";
    }

    //体重-评价
    public static String weightEvaluate(Object heightObj, Object weightObj) {
        if (null == heightObj || StringUtils.isEmpty(heightObj.toString())) {
            return "-";
        }
        if (null == weightObj || StringUtils.isEmpty(weightObj.toString())) {
            return "-";
        }
        double height = Double.parseDouble(heightObj.toString());
        double weight = Double.parseDouble(weightObj.toString());
        double one = (height - 105) * 0.9;
        double two = (height - 105) * 1.1;
        if (weight < one) {
            return styleStatus("偏低");
        } else if (weight > two) {
            return styleStatus("偏高");
        } else {
            return "正常";
        }
    }

    //体质指数(BMI)-评价
    public static String bmiEvaluate(Object hwBmiObj) {
        if (null == hwBmiObj || StringUtils.isEmpty(hwBmiObj.toString())) {
            return "-";
        }
        double hwBmi = Double.parseDouble(hwBmiObj.toString());
        if (hwBmi < 18.5) {
            return styleStatus("偏瘦");
        } else if (hwBmi >= 18.5 && hwBmi <= 23.9) {
            return "正常";
        } else if (hwBmi > 23.9 && hwBmi < 28) {
            return styleStatus("超重");
        } else if (hwBmi >= 28) {
            return styleStatus("肥胖");
        }
        return "-";
    }

    //体温-评价
    public static String templatureEvaluate(Object templatureObj) {
        if (null == templatureObj || StringUtils.isEmpty(templatureObj.toString())) {
            return "-";
        }
        double templature = Double.parseDouble(templatureObj.toString());
        if (templature < 36.1) {
            return styleStatus("偏低");
        } else if (templature >= 36.1 && templature <= 37) {
            return "正常";
        } else if (templature > 37) {
            return styleStatus("偏高");
        }
        return "-";
    }

    //左眼视力-评价
    public static String leftEyesightEvaluate(Object leftEyesightObj) {
        if (null == leftEyesightObj || StringUtils.isEmpty(leftEyesightObj.toString())) {
            return "-";
        }
        double leftEyesight = Double.parseDouble(leftEyesightObj.toString());
        if (leftEyesight < 5.0) {
            return styleStatus("偏低");
        } else if (leftEyesight >= 5.0) {
            return "正常";
        }
        return "-";
    }

    //右眼视力-评价
    public static String rightEyesightEvaluate(Object rightEyesightObj) {
        if (null == rightEyesightObj || StringUtils.isEmpty(rightEyesightObj.toString())) {
            return "-";
        }
        double rightEyesight = Double.parseDouble(rightEyesightObj.toString());
        if (rightEyesight < 5.0) {
            return styleStatus("偏低");
        } else if (rightEyesight >= 5.0) {
            return "正常";
        }
        return "-";
    }

    //脂肪率-评价
    public static String fatRateEvaluate(Object age, Object sex, Object fatRateObj) {
        if (null == age || null == sex || null == fatRateObj) {
            return "-";
        }
        if (StringUtils.isEmpty(age.toString()) || StringUtils.isEmpty(sex.toString()) || StringUtils.isEmpty(fatRateObj.toString())) {
            return "-";
        }
        String sexStr = String.valueOf(new Double(sex.toString()).intValue());
        if (StringUtils.equals("0", sexStr)) {
            return "-";
        }
        double fatRate = Double.parseDouble(fatRateObj.toString());
        Integer ageInt = new Double(age.toString()).intValue();
        switch (sexStr) {
            case "1"://男
                if (ageInt <= 39) {
                    if (fatRate < 18) {
                        return styleStatus("偏低");
                    } else if (fatRate >= 18 && fatRate <= 23) {
                        return "正常";
                    } else if (fatRate > 23) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 40 && ageInt < 55) {
                    if (fatRate < 19) {
                        return styleStatus("偏低");
                    } else if (fatRate >= 19 && fatRate <= 24) {
                        return "正常";
                    } else if (fatRate > 24) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 55) {
                    if (fatRate < 20) {
                        return styleStatus("偏低");
                    } else if (fatRate >= 20 && fatRate <= 25) {
                        return "正常";
                    } else if (fatRate > 25) {
                        return styleStatus("偏高");
                    }
                }
                break;
            case "2":
                if (ageInt <= 39) {
                    if (fatRate < 21) {
                        return styleStatus("偏低");
                    } else if (fatRate >= 21 && fatRate <= 25) {
                        return "正常";
                    } else if (fatRate > 25) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 40 && ageInt < 55) {
                    if (fatRate < 22) {
                        return styleStatus("偏低");
                    } else if (fatRate >= 22 && fatRate <= 26) {
                        return "正常";
                    } else if (fatRate > 26) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 55) {
                    if (fatRate < 23) {
                        return styleStatus("偏低");
                    } else if (fatRate >= 23 && fatRate <= 27) {
                        return "正常";
                    } else if (fatRate > 27) {
                        return styleStatus("偏高");
                    }
                }
                break;
        }
        return "-";
    }

    //脂肪量-评价
    public static String fatEvaluate() {

        return "";
    }

    //去脂体重-评价
    public static String leanBodyWeightEvaluate() {

        return "";
    }

    //水分率-评价
    public static String waterRateEvaluate(Object sex, Object waterRateObj) {
        if (null == waterRateObj || null == sex) {
            return "-";
        }
        if (StringUtils.isEmpty(waterRateObj.toString()) || StringUtils.isEmpty(sex.toString())) {
            return "-";
        }
        String sexStr = String.valueOf(new Double(sex.toString()).intValue());
        if (StringUtils.equals("0", sexStr)) {
            return "-";
        }
        double waterRate = Double.parseDouble(waterRateObj.toString());
        switch (sexStr) {
            case "1"://男
                if (waterRate < 50) {
                    return styleStatus("偏低");
                } else if (waterRate >= 50 && waterRate <= 65) {
                    return "正常";
                } else if (waterRate > 65) {
                    return styleStatus("偏高");
                }
                break;
            case "2":
                if (waterRate < 45) {
                    return styleStatus("偏低");
                } else if (waterRate >= 45 && waterRate <= 55) {
                    return "正常";
                } else if (waterRate > 55) {
                    return styleStatus("偏高");
                }
                break;
        }
        return "-";
    }

    //水分量-评价
    public static String waterEvaluate() {

        return "";
    }

    //骨量-评价
    public static String boneMassEvaluate() {

        return "";
    }

    //肌肉量-评价
    public static String muscleMassEvaluate() {

        return "";
    }

    //肌肉率-评价
    public static String muscleRateEvaluate(Object age, Object sex, Object muscleRateObj) {
        if (null == age || null == sex || null == muscleRateObj) {
            return "-";
        }
        if (StringUtils.isEmpty(age.toString()) || StringUtils.isEmpty(sex.toString()) || StringUtils.isEmpty(muscleRateObj.toString())) {
            return "-";
        }
        String sexStr = String.valueOf(new Double(sex.toString()).intValue());
        if (StringUtils.equals("0", sexStr)) {
            return "-";
        }
        Integer ageInt = new Double(age.toString()).intValue();
        double muscleRate = Double.parseDouble(muscleRateObj.toString());
        switch (sexStr) {
            case "1"://男
                if (ageInt < 15) {
                    if (muscleRate < 44) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 44 && muscleRate <= 57) {
                        return "正常";
                    } else if (muscleRate > 57) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 15 && ageInt <= 19) {
                    if (muscleRate < 43) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 43 && muscleRate <= 56) {
                        return "正常";
                    } else if (muscleRate > 56) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 20 && ageInt <= 29) {
                    if (muscleRate < 42) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 42 && muscleRate <= 55) {
                        return "正常";
                    } else if (muscleRate > 55) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 30 && ageInt <= 39) {
                    if (muscleRate < 41) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 41 && muscleRate <= 54) {
                        return "正常";
                    } else if (muscleRate > 54) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 40 && ageInt <= 49) {
                    if (muscleRate < 40) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 40 && muscleRate <= 50) {
                        return "正常";
                    } else if (muscleRate > 50) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 50 && ageInt <= 59) {
                    if (muscleRate < 39) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 39 && muscleRate <= 48) {
                        return "正常";
                    } else if (muscleRate > 48) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 60 && ageInt <= 69) {
                    if (muscleRate < 38) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 38 && muscleRate <= 47) {
                        return "正常";
                    } else if (muscleRate > 47) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 70) {
                    if (muscleRate < 37) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 37 && muscleRate <= 46) {
                        return "正常";
                    } else if (muscleRate > 46) {
                        return styleStatus("偏高");
                    }
                }
                break;
            case "2":
                if (ageInt < 15) {
                    if (muscleRate < 36) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 36 && muscleRate <= 43) {
                        return "正常";
                    } else if (muscleRate > 43) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 15 && ageInt <= 19) {
                    if (muscleRate < 35) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 35 && muscleRate <= 41) {
                        return "正常";
                    } else if (muscleRate > 41) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 20 && ageInt <= 29) {
                    if (muscleRate < 34) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 34 && muscleRate <= 39) {
                        return "正常";
                    } else if (muscleRate > 39) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 30 && ageInt <= 39) {
                    if (muscleRate < 33) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 33 && muscleRate <= 38) {
                        return "正常";
                    } else if (muscleRate > 38) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 40 && ageInt <= 49) {
                    if (muscleRate < 31) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 31 && muscleRate <= 36) {
                        return "正常";
                    } else if (muscleRate > 36) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 50 && ageInt <= 59) {
                    if (muscleRate < 29) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 29 && muscleRate <= 34) {
                        return "正常";
                    } else if (muscleRate > 34) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 60 && ageInt <= 69) {
                    if (muscleRate < 28) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 28 && muscleRate <= 33) {
                        return "正常";
                    } else if (muscleRate > 33) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 70) {
                    if (muscleRate < 27) {
                        return styleStatus("偏低");
                    } else if (muscleRate >= 27 && muscleRate <= 32) {
                        return "正常";
                    } else if (muscleRate > 32) {
                        return styleStatus("偏高");
                    }
                }
                break;
        }
        return "-";
    }

    //内脏脂肪-评价
    public static String visceralFatEvaluate(Object visceralFatObj) {
        if (null == visceralFatObj || StringUtils.isEmpty(visceralFatObj.toString())) {
            return "-";
        }
        double visceralFat = Double.parseDouble(visceralFatObj.toString());
        if (visceralFat < 1) {
            return styleStatus("偏低");
        } else if (visceralFat >= 1 && visceralFat <= 9) {
            return "正常";
        } else if (visceralFat > 9) {
            return styleStatus("偏高");
        }
        return "-";
    }

    //基础代谢-评价
    public static String basalMetabolismEvaluate(Object sex, Object age, Object basalMetabolismObj) {
        if (null == age || null == sex || null == basalMetabolismObj) {
            return "-";
        }
        if (StringUtils.isEmpty(age.toString()) || StringUtils.isEmpty(sex.toString()) || StringUtils.isEmpty(basalMetabolismObj.toString())) {
            return "-";
        }
        String sexStr = String.valueOf(new Double(sex.toString()).intValue());
        if (StringUtils.equals("0", sexStr)) {
            return "-";
        }
        Integer ageInt = new Double(age.toString()).intValue();
        Integer basalMetabolism = new Double(basalMetabolismObj.toString()).intValue();
        switch (sexStr) {
            case "1":
                if (ageInt < 30) {
                    if (basalMetabolism < 1395) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 1395 && basalMetabolism <= 1705) {
                        return "正常";
                    } else if (basalMetabolism > 1705) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 30 && ageInt <= 49) {
                    if (basalMetabolism < 1350) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 1350 && basalMetabolism <= 1650) {
                        return "正常";
                    } else if (basalMetabolism > 1650) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 50 && ageInt <= 70) {
                    if (basalMetabolism < 1215) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 1215 && basalMetabolism <= 1485) {
                        return "正常";
                    } else if (basalMetabolism > 1485) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt > 70) {
                    if (basalMetabolism < 1098) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 1098 && basalMetabolism <= 1342) {
                        return "正常";
                    } else if (basalMetabolism > 1342) {
                        return styleStatus("偏高");
                    }
                }
                break;
            case "2":
                if (ageInt < 30) {
                    if (basalMetabolism < 1089) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 1089 && basalMetabolism <= 1331) {
                        return "正常";
                    } else if (basalMetabolism > 1331) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 30 && ageInt <= 49) {
                    if (basalMetabolism < 1053) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 1053 && basalMetabolism <= 1287) {
                        return "正常";
                    } else if (basalMetabolism > 1287) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt >= 50 && ageInt <= 70) {
                    if (basalMetabolism < 999) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 999 && basalMetabolism <= 1221) {
                        return "正常";
                    } else if (basalMetabolism > 1221) {
                        return styleStatus("偏高");
                    }
                }
                if (ageInt > 70) {
                    if (basalMetabolism < 909) {
                        return styleStatus("偏低");
                    } else if (basalMetabolism >= 909 && basalMetabolism <= 1111) {
                        return "正常";
                    } else if (basalMetabolism > 1111) {
                        return styleStatus("偏高");
                    }
                }
                break;
        }
        return "-";
    }

    //体型-评价
    public static String buildEvaluate() {

        return "";
    }

    //收缩压(高压)-评价
    public static String heightPressureEvaluate(Object heightPressureObj) {
        if (null == heightPressureObj || StringUtils.isEmpty(heightPressureObj.toString())) {
            return "-";
        }
        double heightPressure = Double.parseDouble(heightPressureObj.toString());
        if (heightPressure < 90) {
            return styleStatus("低压");
        } else if (heightPressure >= 90 && heightPressure <= 139) {
            return "正常";
        } else if (heightPressure >= 140 && heightPressure <= 159) {
            return styleStatus("轻度高血压");
        } else if (heightPressure >= 160 && heightPressure <= 179) {
            return styleStatus("中度高血压");
        } else if (heightPressure >= 180) {
            return styleStatus("重度高血压");
        }
        return "-";
    }

    //舒张压(低压)-评价
    public static String lowPressureEvaluate(Object lowPressureObj) {
        if (null == lowPressureObj || StringUtils.isEmpty(lowPressureObj.toString())) {
            return "-";
        }
        double lowPressure = Double.parseDouble(lowPressureObj.toString());
        if (lowPressure < 60) {
            return styleStatus("低压");
        } else if (lowPressure >= 60 && lowPressure <= 89) {
            return "正常";
        } else if (lowPressure >= 90 && lowPressure <= 99) {
            return styleStatus("轻度高血压");
        } else if (lowPressure >= 100 && lowPressure <= 109) {
            return styleStatus("中度高血压");
        } else if (lowPressure >= 110) {
            return styleStatus("重度高血压");
        }
        return "-";
    }

    //脉搏-评价
    public static String pulseEvaluate(Object pulseObj) {
        if (null == pulseObj || StringUtils.isEmpty(pulseObj.toString())) {
            return "-";
        }
        double pulse = Double.parseDouble(pulseObj.toString());
        if (pulse < 60) {
            return styleStatus("偏低");
        } else if (pulse >= 60 && pulse <= 100) {
            return "正常";
        } else if (pulse > 100) {
            return styleStatus("偏高");
        }
        return "-";
    }

    //色弱检测-评价
    public static String colorScoreEvaluate(Object colorScoreObj) {
        if (null == colorScoreObj || StringUtils.isEmpty(colorScoreObj.toString())) {
            return "-";
        }
        double colorScore = Double.parseDouble(colorScoreObj.toString());
        if (colorScore < 5) {
            return styleStatus("倾向色弱");
        } else if (colorScore >= 5) {
            return "正常";
        }
        return "-";
    }
}
